<?php

/**
 * Ticket filter form.
 *
 * @package    help
 * @subpackage filter
 * @author     Evgeny Babin <psylosss@gmail.com>
 * @version    SVN: $Id: sfDoctrineFormFilterTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class TicketFormFilter extends BaseTicketFormFilter
{
  public function configure()
  {
    $user=sfContext::getInstance()->getUser();
    
    //Даем выбирать только из своих проектов
    if (!$user->hasCredential('manage_tickets_in_all_projects'))
    {
      $projects=array(''=>'Все проекты');
      foreach ($user->getGuardUser()->Profile->Projects as $project)
        $projects[$project->id]=$project->name;
      
      $this->widgetSchema['project_id']=new sfWidgetFormChoice(array(
        'choices'=>$projects,
        'multiple'=>false,
      ));
    }
    
    //Среди ответственных видим только тех, с кем разрешено общаться
    if (!$user->hasCredential('manage_tickets_in_all_projects'))
    {
      $users=array(
        ''=>'Любой',
        $user->getGuardUser()->Profile->id=>'[Я]',
        );
      foreach ($user->getGuardUser()->Profile->AllowInteractUsers as $user)
        $users[$user->id]=$user->User->username.' ('.$user->fullname.')';
      
      $this->widgetSchema['current_user_id']=new sfWidgetFormChoice(array(
        'choices'=>$users,
        'multiple'=>false,
      ));
    }
    
  }
}
